package com.dupt.web.controller.assemble;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dupt.common.annotation.Log;
import com.dupt.common.core.controller.BaseController;
import com.dupt.common.core.domain.AjaxResult;
import com.dupt.common.enums.BusinessType;
import com.dupt.system.domain.MaterialList;
import com.dupt.system.service.IMaterialListService;
import com.dupt.common.utils.poi.ExcelUtil;
import com.dupt.common.core.page.TableDataInfo;

/**
 * 组装用料清单Controller
 * 
 * @author zhuanyu.sun
 * @date 2025-07-05
 */
@RestController
@RequestMapping("/system/list")
public class MaterialListController extends BaseController
{
    @Autowired
    private IMaterialListService materialListService;

    /**
     * 查询组装用料清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:list')")
    @GetMapping("/list")
    public TableDataInfo list(MaterialList materialList)
    {
        startPage();
        List<MaterialList> list = materialListService.selectMaterialListList(materialList);
        return getDataTable(list);
    }

    /**
     * 导出组装用料清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:list:export')")
    @Log(title = "组装用料清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialList materialList)
    {
        List<MaterialList> list = materialListService.selectMaterialListList(materialList);
        ExcelUtil<MaterialList> util = new ExcelUtil<MaterialList>(MaterialList.class);
        util.exportExcel(response, list, "组装用料清单数据");
    }

    /**
     * 获取组装用料清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:list:query')")
    @GetMapping(value = "/{materialListId}")
    public AjaxResult getInfo(@PathVariable("materialListId") Long materialListId)
    {
        return success(materialListService.selectMaterialListByMaterialListId(materialListId));
    }

    /**
     * 新增组装用料清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:add')")
    @Log(title = "组装用料清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MaterialList materialList)
    {
        return toAjax(materialListService.insertMaterialList(materialList));
    }

    /**
     * 修改组装用料清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:edit')")
    @Log(title = "组装用料清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MaterialList materialList)
    {
        return toAjax(materialListService.updateMaterialList(materialList));
    }

    /**
     * 删除组装用料清单
     */
    @PreAuthorize("@ss.hasPermi('system:list:remove')")
    @Log(title = "组装用料清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{materialListIds}")
    public AjaxResult remove(@PathVariable Long[] materialListIds)
    {
        return toAjax(materialListService.deleteMaterialListByMaterialListIds(materialListIds));
    }
}
